package com.ggh.jinjilive.dialog.adapter;

import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemMallGoodsBinding;
import com.ggh.jinjilive.databinding.ItemSearchBarBinding;
import com.ggh.jinjilive.databinding.ItemSelectGoodsBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.listener.AddOnClickListener;
import com.ggh.jinjilive.mobile.mall.MallGoods;

import java.util.List;

public class SelectGoodsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<MallGoods> mallGoodsList;
    public void setAdd(List<MallGoods> mallGoodsList) {
        this.mallGoodsList = mallGoodsList;
        notifyDataSetChanged();
    }

    public void ADD(List<MallGoods> mallGoodsList) {
        if(null !=  this.mallGoodsList){
            this.mallGoodsList.addAll(mallGoodsList);
        }else {
            this.mallGoodsList = mallGoodsList;
        }
        notifyDataSetChanged();
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemSelectGoodsBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_select_goods, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
       if(recyclerViewholder instanceof ItemViewHolder){
            ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
            MallGoods mallGoods = mallGoodsList.get(position);
            if (null != mallGoods) {
                //图片
                Glide.with(holder.binding.imgPortrait).load(mallGoods.getImg()).into(holder.binding.imgPortrait);
//                //名称
//                holder.binding.tvName.setText(mallGoods.getName());
//                //价格
//                holder.binding.tvPrice.setText("¥" + mallGoods.getPrice());
//                //已购
//                holder.binding.tvSales.setText(mallGoods.getSales() + "人已购");
//                //内容
//                holder.binding.tvDescribes.setText(mallGoods.getDescribes());
//                //
//                holder.binding.llGoods.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if(null != addItemOnClickListener){
//                            addItemOnClickListener.onSkipClicked(position,mallGoods);
//                        }
//                    }
//                });
            }
        }

    }

    @Override
    public int getItemCount() {
        return null == mallGoodsList ? 0 : mallGoodsList.size();
    }



    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemSelectGoodsBinding binding;
        public ItemViewHolder(@NonNull ItemSelectGoodsBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}